home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / gfx / misc / gnuplot-3.7src.lha / gnuplot-3.7src / gnuplot-3.7.lha / gnuplot-3.7 / term / dxf.trm < prev    next >
Text File  |  1998-12-14  |  13KB  |  408 lines

  1. /*
  2.  * $Id: dxf.trm,v 1.15 1998/04/14 00:17:37 drd Exp $
  3.  *
  4.  */
  5.  
  6. /* GNUPLOT - dxf.trm */
  7.  
  8. /*[
  9.  * Copyright 1991 - 1993, 1998
  10.  *
  11.  * Permission to use, copy, and distribute this software and its
  12.  * documentation for any purpose with or without fee is hereby granted,
  13.  * provided that the above copyright notice appear in all copies and
  14.  * that both that copyright notice and this permission notice appear
  15.  * in supporting documentation.
  16.  *
  17.  * Permission to modify the software is granted, but not the right to
  18.  * distribute the complete modified source code.  Modifications are to
  19.  * be distributed as patches to the released version.  Permission to
  20.  * distribute binaries produced by compiling modified sources is granted,
  21.  * provided you
  22.  *   1. distribute the corresponding source modifications from the
  23.  *    released version in the form of a patch file along with the binaries,
  24.  *   2. add special version identification to distinguish your version
  25.  *    in addition to the base release version number,
  26.  *   3. provide your name and address as the primary contact for the
  27.  *    support of your modified version, and
  28.  *   4. retain our contact information in regard to use of the base
  29.  *    software.
  30.  * Permission to distribute the released version of the source code along
  31.  * with corresponding source modifications in the form of a patch file is
  32.  * granted with same provisions 2 through 4 for binary distributions.
  33.  *
  34.  * This software is provided "as is" without express or implied warranty
  35.  * to the extent permitted by applicable law.
  36. ]*/
  37.  
  38. /*
  39.  * This file is included by ../term.c.
  40.  *
  41.  * This terminal driver supports:
  42.  *   AutoCad (Release 10.x) dxf file format (import with AutoCad dxfin command)
  43.  *
  44.  *
  45.  * AUTHOR
  46.  *   Florian Hiss  (fhis1231@w204zrz.zrz.tu-berlin.de)
  47.  *
  48.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  49. */
  50.  
  51. /*
  52.  * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
  53.  */
  54.  
  55. #include "driver.h"
  56.  
  57. #ifdef TERM_REGISTER
  58. register_term(dxf)
  59. #endif
  60.  
  61. #ifdef TERM_PROTO
  62. TERM_PUBLIC void DXF_init __PROTO((void));
  63. TERM_PUBLIC void DXF_graphics __PROTO((void));
  64. TERM_PUBLIC void DXF_text __PROTO((void));
  65. TERM_PUBLIC void DXF_linetype __PROTO((int linetype));
  66. TERM_PUBLIC void DXF_move __PROTO((unsigned int x, unsigned int y));
  67. TERM_PUBLIC void DXF_vector __PROTO((unsigned int ux, unsigned int uy));
  68. TERM_PUBLIC void DXF_put_text __PROTO((unsigned int x, unsigned int y,
  69.                        char str[]));
  70. TERM_PUBLIC int DXF_text_angle __PROTO((int ang));
  71. TERM_PUBLIC int DXF_justify_text __PROTO((enum JUSTIFY mode));
  72. TERM_PUBLIC void DXF_reset __PROTO((void));
  73.  
  74. #define DXF_XMAX (120.0 * DXF_UNIT)
  75. #define DXF_YMAX (80.0 * DXF_UNIT)
  76. #define DXF_HTIC (0.01 * DXF_XMAX)    /* 1.0 percent */
  77. #define DXF_VTIC (0.01 * DXF_YMAX)    /* 1.0 percent */
  78. #define DXF_HCHAR (0.014 * DXF_XMAX)    /* 1.4 percent */
  79. #define DXF_VCHAR (0.026 * DXF_YMAX)    /* 2.6 percent */
  80. #endif /* TERM_PROTO */
  81.  
  82. #ifndef TERM_PROTO_ONLY
  83. #ifdef TERM_BODY
  84.  
  85. #define DXF_UNIT 60.0
  86. #define LINEWIDTH 0.0351    /* default line width is 1 pt */
  87.  
  88. /* 120 (autocad units) wide by 80 (autocad units) high (default)
  89.  * use the GNUPLOT 'set size' command to change the defaults */
  90. /* actual text height */
  91. #define DXF_TEXTHEIGHT (0.7 * DXF_VCHAR)
  92. /* actual text width, only a guess, we don't know the width of
  93.  * a character of given height of the AutoCad STANDARD text font,
  94.  * so change it if you like */
  95. #define DXF_TEXTWIDTH (0.7 * DXF_HCHAR)
  96. /* number of line types we support. see below  */
  97. #define DXF_LINE_TYPES 7
  98. /* number of layers used for the drawing. see below */
  99. #define MAX_LAYER 7
  100. /* line type scaling */
  101. #define LT_SCALE 1
  102.  
  103. static unsigned int DXF_posx;
  104. static unsigned int DXF_posy;
  105. /* linetype is mapped to a layer. see below. */
  106. static unsigned int dxf_linetype;
  107. enum JUSTIFY dxf_justify = LEFT;
  108. static float dxf_angle = 0.0;    /* either 0 (horizontal) or 90.0 (vertical) */
  109.  
  110. /* text style used in the entire drawing */
  111. static char *text_style = "STANDARD";
  112. /* text always resides on layer 0 */
  113. #define TEXT_LAYER 0
  114. /* each linetype resides on its own layer. each layer has its own color.
  115.  * this avoids difficulties that AutoCad has with proper scaling of
  116.  * the linetypes.
  117.  * change the colors according to your needs */
  118. static char *layer_name[] ={ "0", "1", "2", "3", "4", "5", "6" };
  119. /* the colours are white, red, yellow, green, cyan, blue, magenta.
  120.  * change them according to your needs.
  121.  * when using a black and white plotting device the colours map to different
  122.  * line thicknesses. see description of AutoCad print / plot command */
  123. static char *layer_colour[] = { "7", "1", "2", "3", "4", "5", "6" };
  124. /* support line types AutoCad has to offer by default. */
  125. static char *layer_lines[] = { "CONTINUOUS", "DASHED", "HIDDEN", "CENTER",
  126.                   "PHANTOM", "DOT", "DASHDOT" };
  127.  
  128. static TBOOLEAN vector_was_last = FALSE;
  129.  
  130. TERM_PUBLIC void DXF_init()
  131. {
  132.     DXF_posx = DXF_posy = 0;
  133.     dxf_linetype = 0;
  134.     dxf_angle = 0.0;
  135.     vector_was_last = FALSE;
  136. }
  137.  
  138. TERM_PUBLIC void DXF_graphics()
  139. {
  140.     register struct termentry *t = term;
  141.     int i;
  142.     static char GPFAR dxfi1[] = "\
  143. 999\n\
  144. %% GNUPLOT: dxf file for AutoCad\n\
  145.   0\nSECTION\n  2\nHEADER\n\
  146.   9\n$EXTMIN\n\
  147.  10\n0.000\n 20\n0.000\n\
  148.   9\n$EXTMAX\n\
  149.  10\n%-6.3f\n 20\n%-6.3f\n\
  150.   9\n$LIMMIN\n\
  151.  10\n0.000\n 20\n0.000\n\
  152.   9\n$LIMMAX\n\
  153.  10\n%-6.3f\n 20\n%-6.3f\n\
  154.   9\n$TEXTSTYLE\n  7\n%s\n\
  155.   9\n$TEXTSIZE\n 40\n%-6.3f\n\
  156.   9\n$PLINEWID\n 40\n%-6.4f\n\
  157.   9\n$LTSCALE\n  40\n%-6.3f\n\
  158.   9\n$COORDS\n 70\n  1\n\
  159.   9\n$CELTYPE\n 6\nBYLAYER\n\
  160.   9\n$CLAYER\n  8\n0\n\
  161.   9\n$CECOLOR\n 62\n   %s\n\
  162.   9\n$MENU\n  1\nacad\n\
  163.   0\nENDSEC\n\
  164.   0\nSECTION\n  2\nTABLES\n";
  165.     static char GPFAR dxfi2[] = "\
  166. 0\nTABLE\n  2\nLTYPE\n 70\n    %d\n\
  167. 0\nLTYPE\n  2\nCONTINUOUS\n 70\n    64\n\
  168.   3\nSolid line\n 72\n    65\n 73\n      0\n 40\n0.0\n\
  169.   0\nLTYPE\n  2\nDASHED\n 70\n    64\n\
  170.   3\n__ __ __ __ __ __ __ __ __ __ __ __ __ __ __\n\
  171.  72\n    65\n 73\n     2\n 40\n0.75\n 49\n0.5\n 49\n-0.25\n\
  172.   0\nLTYPE\n  2\nHIDDEN\n 70\n    64\n\
  173.   3\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _\n\
  174.  72\n    65\n 73\n     2\n 40\n0.375\n 49\n0.25\n 49\n-0.125\n\
  175.   0\nLTYPE\n  2\nCENTER\n 70\n    64\n\
  176.   3\n____ _ ____ _ ____ _ ____ _ ____ _ ____ _ ____\n\
  177.  72\n    65\n 73\n     4\n 40\n2.0\n 49\n1.25\n 49\n-0.25\n\
  178.  49\n0.25\n 49\n-0.25\n\
  179.   0\nLTYPE\n  2\nPHANTOM\n 70\n    64\n\
  180.   3\n_____ _ _ _____ _ _ _____ _ _ _____ _ _ ____\n\
  181.  72\n    65\n 73\n     6\n 40\n2.5\n 49\n1.25\n\
  182.  49\n-0.25\n 49\n0.25\n 49\n-0.25\n 49\n0.25\n 49\n-0.25\n\
  183.   0\nLTYPE\n  2\nDOT\n 70\n    64\n\
  184.   3\n...............................................\n\
  185.  72\n    65\n 73\n     2\n 40\n0.25\n 49\n0.0\n 49\n-0.25\n\
  186.   0\nLTYPE\n  2\nDASHDOT\n 70\n    64\n\
  187.   3\n__ . __ . __ . __ . __ . __ . __ . __ . __ . __\n\
  188.  72\n    65\n 73\n     4\n 40\n1.0\n 49\n0.5\n 49\n-0.25\n\
  189.  49\n0.0\n 49\n-0.25\n\
  190.   0\nENDTAB\n";
  191.  
  192.     fprintf(gpoutfile, dxfi1,
  193.         t->xmax / DXF_UNIT, t->ymax / DXF_UNIT,
  194.         t->xmax / DXF_UNIT, t->ymax / DXF_UNIT,
  195.         text_style,
  196.         DXF_TEXTHEIGHT / DXF_UNIT,
  197.         LINEWIDTH,
  198.         (double) LT_SCALE,
  199.         layer_colour[0]);
  200.     /* the linetype table */
  201.     fprintf(gpoutfile, dxfi2, DXF_LINE_TYPES);
  202.     /* the layer table */
  203.     fprintf(gpoutfile, "  0\nTABLE\n  2\nLAYER\n 70\n   %-d\n", MAX_LAYER);
  204.     for (i = 1; i <= MAX_LAYER; i++)
  205.     fprintf(gpoutfile, "  0\nLAYER\n  2\n%s\n 70\n   64\n62\n   %s\n  6\n%s\n", layer_name[i - 1], layer_colour[i - 1], layer_lines[i - 1]);
  206.  
  207.     /* no blocks for insertion */
  208.     /* start the entity section */
  209.     fputs("  0\nENDTAB\n0\nENDSEC\n\
  210.   0\nSECTION\n  2\nBLOCKS\n  0\nENDSEC\n\
  211.   0\nSECTION\n\
  212.   2\nENTITIES\n",
  213.       gpoutfile);
  214. }
  215.  
  216. TERM_PUBLIC void DXF_text()
  217. {
  218.     if (vector_was_last)
  219.     fputs("  0\nSEQEND\n", gpoutfile);
  220.     fputs("  0\nENDSEC\n  0\nEOF\n", gpoutfile);
  221. }
  222.  
  223. TERM_PUBLIC void DXF_linetype(linetype)
  224. int linetype;
  225. {
  226.     linetype = ABS(linetype);
  227.     linetype = linetype % DXF_LINE_TYPES;
  228.     dxf_linetype = linetype;
  229. }
  230.  
  231. TERM_PUBLIC void DXF_move(x, y)
  232. unsigned int x, y;
  233. {
  234.     DXF_posx = x;
  235.     DXF_posy = y;
  236.     if (vector_was_last)
  237.     fputs("  0\nSEQEND\n", gpoutfile);
  238.     vector_was_last = FALSE;
  239.     fprintf(gpoutfile, "\
  240.   0\nPOLYLINE\n  8\n%s\n 66\n   1\n\
  241.   6\n%s\n\
  242.   0\nVERTEX\n  8\n%s\n\
  243.   6\n%s\n\
  244.  10\n%-6.3f\n 20\n%-6.3f\n 30\n0.000\n",
  245.         layer_name[dxf_linetype],
  246.         layer_lines[dxf_linetype],
  247.         layer_name[dxf_linetype],
  248.         layer_lines[dxf_linetype],
  249.         DXF_posx / DXF_UNIT, DXF_posy / DXF_UNIT);
  250.  
  251. }
  252.  
  253. TERM_PUBLIC void DXF_vector(ux, uy)
  254. unsigned int ux, uy;
  255. {
  256.     DXF_posx = ux;
  257.     DXF_posy = uy;
  258.     vector_was_last = TRUE;
  259.  
  260.     fprintf(gpoutfile, "\
  261.   0\nVERTEX\n  8\n%s\n\
  262.   6\n%s\n\
  263.   10\n%-6.3f\n  20\n%-6.3f\n  30\n0.000\n",
  264.         layer_name[dxf_linetype],
  265.         layer_lines[dxf_linetype],
  266.         DXF_posx / DXF_UNIT, DXF_posy / DXF_UNIT);
  267. }
  268.  
  269. TERM_PUBLIC void DXF_put_text(x, y, str)
  270. unsigned int x, y;
  271. char str[];
  272. {
  273.     int stl;
  274.     float xleftpos, yleftpos, xrightpos, yrightpos;
  275.  
  276.     /* shut up gcc warnings  - SB */
  277.     xleftpos = yleftpos = xrightpos = yrightpos = 1.0;    /* dummy */
  278.     /* ignore empty strings */
  279.     if (str[0] == NUL)
  280.     return;
  281.  
  282.     stl = 0;
  283.     while (str[stl] != NUL)
  284.     ++stl;            /* get string length */
  285.  
  286.     if (vector_was_last)
  287.     fputs("  0\nSEQEND\n", gpoutfile);
  288.     vector_was_last = FALSE;
  289.     fprintf(gpoutfile, "  0\nTEXT\n  8\n%s\n", layer_name[TEXT_LAYER]);
  290.     if (dxf_angle != 90.0) {
  291.     switch (dxf_justify) {
  292.     case LEFT:
  293.         xleftpos = (float) x;
  294.         yleftpos = (float) (y - DXF_VCHAR / 4.0);
  295.         xrightpos = (float) (x + stl * DXF_TEXTWIDTH);
  296.         yrightpos = yleftpos;
  297.         break;
  298.     case RIGHT:
  299.         xleftpos = (float) (x - stl * DXF_TEXTWIDTH);
  300.         yleftpos = (float) (y - DXF_VCHAR / 4.0);
  301.         xrightpos = (float) x;
  302.         yrightpos = yleftpos;
  303.         break;
  304.     case CENTRE:
  305.         xleftpos = (float) (x - stl * DXF_TEXTWIDTH / 2.0);
  306.         yleftpos = (float) (y - DXF_VCHAR / 4.0);
  307.         xrightpos = (float) x;    /* center point */
  308.         yrightpos = yleftpos;
  309.         break;
  310.     }
  311.     } else {
  312.     switch (dxf_justify) {
  313.     case LEFT:
  314.         xleftpos = (float) (x + DXF_VCHAR / 4.0);
  315.         yleftpos = (float) y;
  316.         xrightpos = xleftpos;
  317.         yrightpos = (float) (y + stl * DXF_TEXTWIDTH);
  318.         break;
  319.     case RIGHT:
  320.         xleftpos = (float) (x + DXF_VCHAR / 4.0);
  321.         yleftpos = (float) (y - stl * DXF_HCHAR);
  322.         xrightpos = xleftpos;
  323.         yrightpos = (float) y;
  324.         break;
  325.     case CENTRE:
  326.         xleftpos = (float) (x + DXF_VCHAR / 4.0);
  327.         yleftpos = (float) (y - stl * DXF_TEXTWIDTH / 2.0);
  328.         xrightpos = xleftpos;
  329.         yrightpos = (float) y;    /* center point */
  330.         break;
  331.     }
  332.     }
  333.  
  334.     fprintf(gpoutfile, "\
  335.  10\n%-6.3f\n 20\n%-6.3f\n 30\n0.000\n\
  336.  40\n%-6.3f\n  1\n%s\n 50\n%-6.3f\n\
  337.   7\n%s\n",
  338.         xleftpos / DXF_UNIT, yleftpos / DXF_UNIT,
  339.         DXF_TEXTHEIGHT / DXF_UNIT, str, dxf_angle,
  340.         text_style);
  341.  
  342.     if (dxf_justify != LEFT) {
  343.     fprintf(gpoutfile, " 72\n%d\n\
  344.  11\n%-6.3f\n 21\n%-6.3f\n 31\n0.000\n",
  345.         dxf_justify,
  346.         xrightpos / DXF_UNIT, yrightpos / DXF_UNIT);
  347.     }
  348. }
  349.  
  350. TERM_PUBLIC int DXF_text_angle(ang)
  351. int ang;
  352. {
  353.     dxf_angle = 0.0;
  354.     if (ang == 1)
  355.     dxf_angle = 90.0;
  356.     return (TRUE);
  357. }
  358.  
  359. TERM_PUBLIC int DXF_justify_text(mode)
  360. enum JUSTIFY mode;
  361. {
  362.     dxf_justify = mode;
  363.     return (TRUE);
  364. }
  365.  
  366. TERM_PUBLIC void DXF_reset()
  367. {
  368.     DXF_posx = DXF_posy = 0;
  369. }
  370.  
  371. #endif /* TERM_BODY */
  372.  
  373. #ifdef TERM_TABLE
  374. TERM_TABLE_START(dxf_driver)
  375.   "dxf", "dxf-file for AutoCad (default size 120x80)",
  376.     DXF_XMAX, DXF_YMAX, DXF_VCHAR, DXF_HCHAR,
  377.     DXF_VTIC, DXF_HTIC, options_null, DXF_init, DXF_reset,
  378.     DXF_text, null_scale, DXF_graphics, DXF_move, DXF_vector,
  379.     DXF_linetype, DXF_put_text, DXF_text_angle,
  380.     DXF_justify_text, do_point, do_arrow, set_font_null
  381. TERM_TABLE_END(dxf_driver)
  382.  
  383. #undef LAST_TERM
  384. #define LAST_TERM dxf_driver
  385.  
  386. #endif /* TERM_TABLE */
  387. #endif /* TERM_PROTO_ONLY */
  388.  
  389. #ifdef TERM_HELP
  390. START_HELP(dxf)
  391. "1 dxf",
  392. "?commands set terminal dxf",
  393. "?set terminal dxf",
  394. "?set term dxf",
  395. "?terminal dxf",
  396. "?term dxf",
  397. "?dxf",
  398. " The `dxf` terminal driver creates pictures that can be imported into AutoCad",
  399. " (Release 10.x).  It has no options of its own, but some features of its plots",
  400. " may be modified by other means.  The default size is 120x80 AutoCad units,",
  401. " which can be changed by `set size`.  `dxf` uses seven colors (white, red,",
  402. " yellow, green, cyan, blue and magenta), which can be changed only by",
  403. " modifying the source file.  If a black-and-white plotting device is used, the",
  404. " colors are mapped to differing line thicknesses.  See the description of the",
  405. " AutoCad print/plot command."
  406. END_HELP(dxf)
  407. #endif /* TERM_HELP */
  408.